package com.yfp.common.core.utils;

import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DeviceNumberUtil {
    private static final String DATE_FORMAT = "yyyyMMdd";
    private static final String TYPE_FORMAT = "%02d";


    public static synchronized String generateDeviceNumber(Integer type, Integer sequence) {
        // 获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        // 格式化日期
        String date = now.format(DateTimeFormatter.ofPattern(DATE_FORMAT)).substring(2);

        // 格式化类型
        String formattedType = String.format(TYPE_FORMAT, type);
        // 格ZAZ式化序号
        String formattedSequence = formatSequence(sequence);

        return date + formattedType + formattedSequence;
    }

    private static String formatSequence(int sequence) {
        DecimalFormat decimalFormat = new DecimalFormat("000000");
        return decimalFormat.format(sequence);
    }
}
